home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / swimChar.lua < prev    next >
Text File  |  2004-01-29  |  7KB  |  272 lines

  1. -- elaine walk state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onEnter(function(msg)
  6.         print("swimChar enter ------------------------------------------");
  7.         
  8.         local pool = retrieveStateObject("pool")
  9.         if (pool) then
  10.             getParent().startActivity("swim", pool);
  11.         end
  12.         
  13.  
  14.     end )
  15.     
  16.     onExit(function(msg)
  17.         print("swimChar exit ------------------------------------------");
  18.         
  19.         local pool = retrieveStateObject("pool")
  20.         if (pool) then
  21.             getParent().stopActivity("swim", pool);
  22.         end
  23.  
  24.     end )
  25.     
  26.     
  27.     onMsg("goAway", function(msg)
  28.         print("onMsg goAway(swim)-----------------------------------------------------------");
  29.         
  30.         if (isWalking()) then return end;
  31.         
  32.         local minDist = random(1,10);
  33.         local target = getParent().findPointNear(minDist, 10.0);
  34.         if (target) then
  35.             getParent().queueWalkActionPoint("pm_swim", target, true);
  36.         else
  37.             print("goAway(swim) no target");
  38.         end
  39.     end )
  40.     
  41.     
  42. --    onMsg("leavePool", function(msg)
  43. --    
  44. --        local exitPoints = pool.getExitPoints(getParent());
  45. --        for p = 1, getn(exitPoints) do
  46. --            print(" exitPoints " .. p);
  47. --            local actionPoint = exitPoints[p];
  48. --                                                
  49. --            -- get the walk state object
  50. --            if (walkToActionPoint(actionPoint)) then
  51. --                print("leave pool");
  52. --                storeData("exit", true);
  53. --                return
  54. --            end
  55. --        end
  56. --        
  57. --    end )
  58.     
  59.     
  60.  
  61.     onMsg("queue", function(msg)
  62.         nextAction();
  63.         print("stop swim");
  64.     end )                
  65.  
  66.     
  67.     
  68. --    state("goAway")
  69. --        onEnter(function(msg)
  70. --            print("goAway onEnter");
  71. --            local minDist = random(1,10);
  72. --            local target = getParent().findPointNear(minDist, 10.0);
  73. --            if (target) then
  74. --                getParent().queueWalkActionPoint("pm_swim", target, true);
  75. --            else
  76. --                print("no target");
  77. --            end
  78. --        end )    
  79.     
  80.     
  81.     -- stand
  82.     state("stand")
  83.         onEnter(function(msg)
  84.             startAnimation("swimmingStand");
  85.             sendDelayedMsgThis("makeDrop", 1000);
  86.             actionComplete();
  87.             getParent().loopSound("swimOnPlace");
  88.         end )
  89.  
  90.         onExit(function(msg)
  91.             getParent().stopSound("swimOnPlace");
  92.         end )
  93.  
  94.         onMsg("makeDrop", function(msg)        
  95.             getParent().createWaterDrop(0.2, 200);
  96.             sendDelayedMsgThis("makeDrop", 1000);
  97.         end )    
  98.  
  99.         onMsg("end", function(msg)
  100.             startAnimation("swimmingStand");
  101.             actionComplete();
  102.         end )    
  103.  
  104.                     
  105.         
  106.     -- walk
  107.     state("walk")
  108.         onEnter(function(msg)
  109.             print("walk onEnter " .. getParent().getCharacterName());
  110.             
  111.             local pool = retrieveStateObject("pool")
  112.             
  113.             getParent().loopSound("swimLoop");
  114.             
  115.             local walkAnim = "swimmingSlow";
  116.             storeData("walkAnim", walkAnim);
  117.                     
  118.             startWalk(walkAnim, "swimmingStand");
  119.  
  120.             if (pool.isCharacterLeavingPool(getParent())) then
  121.                                 
  122. --                local groundActionPoint = getParent().walkSO.getWantedActionPoint();
  123. --                storeData("groundActionPoint", getParent().walkSO.getWantedActionPoint());
  124. --                storeData("afterWalkMsg", getParent().getAfterWalkMsg(0));
  125.  
  126.                 local topEntry = getParent().getActivityQueueEntry(0);
  127.                 if (topEntry) then
  128.                     storeData("groundActionPoint", topEntry.getTarget());
  129.                     storeData("afterWalkMsg", getParent().getAfterWalkMsg(0));
  130.                 end
  131.  
  132.                 
  133.                 local exitPoints = pool.getExitPoints(getParent());
  134.                 for p = 1, getn(exitPoints) do
  135.                     print(" exitPoints " .. p);
  136.                     local actionPoint = exitPoints[p];
  137.                                                         
  138.                     -- get the walk state object
  139.                     if (walkToActionPoint(actionPoint)) then
  140.                         print("leave pool");
  141.                         storeData("exit", true);
  142.                         return
  143.                     end
  144.                 
  145.                 end
  146.                 print("no path found");
  147.                 --getParent().setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  148.                 
  149.             else
  150.                 print("stay in pool");
  151.             end
  152.  
  153.             storeData("exit", false);
  154.             sendDelayedMsgThis("makeDrop", 250);
  155.         end )
  156.         
  157.         onExit(function(msg)
  158.             getParent().stopSound("swimLoop");
  159.         end )
  160.  
  161.         -- target changed durring walk
  162.         onMsg("targetChanged", function(msg)
  163.         
  164.             print("target changed durring walk " .. getParent().getCharacterName());
  165.         
  166.             local pool = retrieveStateObject("pool")
  167.             if (pool.isCharacterLeavingPool(getParent())) then
  168.                                 
  169. --                local groundActionPoint = getParent().walkSO.getWantedActionPoint();
  170. --                storeData("groundActionPoint", getParent().walkSO.getWantedActionPoint());
  171.  
  172.                 local topEntry = getParent().getActivityQueueEntry(0);
  173.                 if (topEntry) then
  174.                     storeData("groundActionPoint", topEntry.getTarget());
  175.                     storeData("afterWalkMsg", getParent().getAfterWalkMsg(0));
  176.                 end
  177.  
  178.                 
  179.                 
  180.                 local exitPoints = pool.getExitPoints(getParent());
  181.                 for p = 1, getn(exitPoints) do
  182.                     print(" exitPoints " .. p);
  183.                     local actionPoint = exitPoints[p];
  184.                                                         
  185.                     -- get the walk state object
  186.                     if (walkToActionPoint(actionPoint)) then
  187.                         print("leave pool");
  188.                         storeData("exit", true);
  189.                         return
  190.                     end
  191.                 
  192.                 end
  193.                 
  194.                 print("no exit point found");
  195.                 storeData("exit", false);
  196.             else
  197.                 print("stay in pool");
  198.                 storeData("exit", false);
  199.             end
  200.  
  201.                 
  202.         end )    
  203.  
  204.         
  205.         onMsg("makeDrop", function(msg)        
  206.             getParent().createWaterDrop(0.2, 500);
  207.             sendDelayedMsgThis("makeDrop", 250);
  208.         end )    
  209.         
  210.         onMsg("next", function(msg)
  211.             if testCancel() then
  212.                 print("next testCancel == true");
  213.                 stopWalk();
  214.                 nextAction();
  215.             else
  216.                 
  217.                 local pool = retrieveStateObject("pool")
  218.                 
  219.                 local walkAnim = retrieveData("walkAnim", "swimming");
  220.                 local newWalkAnim = "swimming";
  221.                 if (pool.isCharacterMovingToEdge(getParent(), 1.5)) then newWalkAnim = "swimmingSlow"; end;
  222.                 storeData("walkAnim", newWalkAnim);
  223.                 
  224.                 --startWalk(newWalkAnim, "swimmingStand");
  225.  
  226.                 if (newWalkAnim == walkAnim) then
  227.                     print("next - startWalk " .. newWalkAnim);
  228.                     startWalk(newWalkAnim, "swimmingStand");
  229.                 else
  230.                     print("next - startWalk changed" .. walkAnim .. " -> " .. newWalkAnim);
  231.                     startWalk(newWalkAnim, "swimmingStand", 1000);
  232.                 end
  233.                 
  234.                 print("next - swim anim " .. newWalkAnim);
  235.             end
  236.         end )    
  237.         
  238.         onMsg("end", function(msg)
  239.             
  240.             if (retrieveData("exit", false) == true) then
  241.                 print("end -> exit");            
  242.                 setState("exitSwim");
  243.             else
  244.                 print("end -> stay");
  245.                 nextAction();            
  246.             end    
  247.  
  248.         end )    
  249.  
  250.     -- walk
  251.     state("exitSwim")
  252.     
  253.         onEnter(function(msg)
  254.             print("exitSwim " .. getParent().getCharacterName());
  255.  
  256.             getParent().replaceQueueEntry(0, "pm_exitPool");
  257.             local groundActionPoint = retrieveData("groundActionPoint");
  258.             if (groundActionPoint) then
  259.                 
  260.                 print("exitSwim queueWalkActionPoint1 queue:" .. getParent().getActivityQueueCount());
  261.                 getParent().pushWalkActionPoint("pm_walk", groundActionPoint, true, retrieveData("afterWalkMsg"));
  262. --                getParent().queueWalkActionPoint("pm_walk", groundActionPoint, true);
  263.                 print("exitSwim queueWalkActionPoint2 queue:" .. getParent().getActivityQueueCount());
  264.             end
  265.             
  266.             exitStateMachine();
  267.         end)
  268.  
  269.     
  270.         
  271. endStateMachine()
  272.